package blackitheima1.BubbleTest;
//冒泡排序法
public class BubbleTest1 {
    public static void main(String[] args) {
        //定义数组
        int[] arr={11,48,22,78,33,98,44,85};
        getNewArray(arr);
    }

    private static void getNewArray(int[] arr) {
        //遍历数组排序
        //外循环-1是每次都会确定一个最值,最后少一次
        for (int i = 0; i < arr.length-1; i++) {
            //内循环-1 :防止索引越界
            //-i :每次都会确定一个数
            for (int j = 0; j < arr.length-1-i; j++) {
                if(arr[j]>arr[j+1]){
                    arr[j]=arr[j]^arr[j+1];
                    arr[j+1]=arr[j]^arr[j+1];
                    arr[j]=arr[j]^arr[j+1];
                }
            }
        }
        //遍历新数组
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i]+" ");
        }
        System.out.println();
    }
}
